<?php

/**
 *   OPENSHOP 数据库管理
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: database.php,v 1.0 2009/06/12 07:35:58 modified $
 *   @author     
 */

define('IN_OS', true); 
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'admin/includes/cls_sql_dump.php'); 
@ini_set('memory_limit', '64M'); 

$current_time  = time() - date('Z'); 
//echo date ('Y-m-d H:i:s',$current_time);

//首先获取当前需要被解挂的订单列表
$sql = 'select relating_order_id from open_order_suspend where process_status = 0 and end_time >0 and end_time <= '.$current_time;
$res = $db->getAll($sql);

$arr = array('process_status' => 0);
$sql = 'update open_order_suspend set process_status = 1 , process_mode = 4 , process_user = "后台计划任务" where relating_order_id = ';

foreach($res as $order_id)
{
	$order_id = $order_id['relating_order_id'];
	$sql_order = 'select order_sn,order_status,shipping_status,pay_status from open_order_info where  order_id = '.$order_id;
	$order = $db->getRow($sql_order);
	
	$db->autoExecute('open_order_info',
        $arr, 'UPDATE', "order_id = '$order_id'");	
	
	$username = '计划任务';
	$current_time  = time() - date('Z');
	
	$sql2 = 'INSERT INTO open_order_action (order_id, action_user, order_status, shipping_status, pay_status, action_note, log_time) ' .
            "SELECT order_id, '$username', '$order[order_status]', '$order[shipping_status]', '$order[pay_status]', '解挂订单-计划任务自动解挂', '" .$current_time. "' " .'FROM open_order_info WHERE order_sn = '.$order['order_sn'];
	$db->query($sql2);
	
    $db->query($sql.$order_id);
}

//每10分钟刷新一次
$t = 10;    
echo "<p style='text-align:center;padding-top:50px;'>自动解挂定时器每".$t."分钟制动执行一次，请不要关闭！<p/>";
echo "<script language='Javascript'> 
                function reflesh(){	 
						document.location.reload(); 
				};
				setTimeout('reflesh()', $t*1000*60) 
        </script>";  

?>